from langgraph.graph import StateGraph,START,END
from typing_extensions import TypedDict
from operator import add
from langgraph.types import Send
from typing import Annotated

"""
节点分发功能：
# 1.创建保存图的状态的字典
# 2.创建智能体
# 3.创建路由 send分发路由自己分发自己6次
# 4.创建带状态的图
# 5.创建节点 节点和智能体绑定，条件边上配置上路由
# 6.编译图
# 7.使用：通过图执行智能体和管理  invoke
"""
class State(TypedDict):
    foo: Annotated[list[str],add]
    f: int

def agent_01(state):
    return {"foo":[state["f"]]}

def dispatch(state):
    return [Send("agent_01",{"f":str(i)}) for i in range(6)]

builder = StateGraph(State)
builder.add_node("agent_01",agent_01)
builder.add_conditional_edges(START,dispatch)
builder.add_edge("agent_01",END)

graph = builder.compile()

r = graph.invoke({"foo":[],"f":"1"})
print(r)